/*
 *	Filename:		ado.h
 *	Author:			Luke Douglas
 *	Date:			11/12/01
 *	Copyright:		(c) 2001-2 Realtime Gaming
 *
 *	History:		luke: 11/12/01	Created
 *					luke: 1/16/02	Cleaned up
 *					luke: 2/3/02	Moved to mbcommon and renamed
 *					brian: 9/16/02	Moved to serv/win32 for use by data collection service - removed some MB specific code
 */

#ifndef _ADO_H_
#define _ADO_H_


/////////////
// IMPORTS //
/////////////

#pragma warning(disable:4146)
#import <MSADO15.dll> rename("EOF", "EndOfFile")
#pragma warning(default:4146)


#define SQLMONEY			INT64									// Alias for SQL money data type


//////////////////
// MORE DEFINES //
//////////////////
// NOTE: Code that includes this library must instantiate a logger and use it to initialize Log
// #define DEBUGMSG			Log::msghdr
// #define ERRORW(x)		Log::msghdr("%s error: %d\n", x, WSAGetLastError())
// #define ERRORG(x)		Log::msghdr("%s error: 0x%x\n", x, GetLastError())
// #define ERRORX			Log::msghdr

// *** Substituted for the above for debugging purposes
#define DEBUGMSG			wprintf
#define ERRORW(x)			wprintf(L"%s error: %d\n", WSAGetLastError())
#define ERRORG(x)			wprintf(L"%s error: 0x%x\n", x, GetLastError())
#define ERRORX				wprintf


/////////////
// METHODS //
/////////////
class ADO
{
private:
	ADODB::_ConnectionPtr pCon;		// ADO connection object
	ADODB::_CommandPtr pCmd;		// ADO command object
	ADODB::_ParameterPtr pPrm;		// ADO parameter object

	BOOL bConnected;	// Set if the Connection object is connected to the database
	int iDelay;			// Current delay to be used between successive executions

	// These are configuration parameters set via the Configure method
	LPWSTR m_szwConnectionString, m_szwUsername, m_szwPassword;
	int m_iMinDelay, m_iDelayStep, m_iMaxDelay;

private:
	BOOL _Execute(int*);

public:
	static void PrintComError(_com_error*, LPWSTR);

	ADO();
	~ADO();

	BOOL Configure(LPWSTR, LPWSTR, LPWSTR, int, int, int);

	BOOL Connect();
	BOOL Disconnect();

	BOOL NewCommand(LPWSTR, LPWSTR, LPWSTR, LPWSTR, int);
	BOOL AddParameter(LPWSTR, BOOL);
	BOOL AddParameter(SQLMONEY, BOOL);
	BOOL AddParameter(int, BOOL);

	BOOL Execute(int*, int*, SQLMONEY[8]);
};


#endif
